import 'package:flutter/material.dart';
import 'package:flutter_lang/flutter_lang.dart';
import 'package:flutter_theme/theme.dart';
import 'package:flutter_theme/theme_utils.dart';
import 'package:route_manager/wx_navigator.dart';
import '../../module_config.dart';
import '../models/wallet_info_model.dart';

class CreateWalletPage extends StatefulWidget {
  final int walletSource;

  CreateWalletPage({Key key, this.walletSource = 0}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _CreateWalletPageState();
}

class _CreateWalletPageState extends State<CreateWalletPage> {
  bool isEmpty = true;
  TextEditingController _walletNameEditController = TextEditingController();
  String sourceTitle =
      '${WXLang.$t("aauthentication_create_wallet", package: ModuleConfig.moduleName)}';

  @override
  void initState() {
    super.initState();
    sourceTitle = widget.walletSource == 0
        ? '${WXLang.$t("authentication_create_wallet", package: ModuleConfig.moduleName)}'
        : '${WXLang.$t("authentication_restore_wallet", package: ModuleConfig.moduleName)}';
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    print("theme======init========>${ThemeUtils.isDark(context)}");
    return Scaffold(
      appBar: AppBar(
        backgroundColor: WXTheme.$c("authentication_header_background"),
        title: Text(sourceTitle),
        brightness: Brightness.dark,
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            Padding(
              padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
              child: TextField(
                  autofocus: true,
                  controller: _walletNameEditController,
                  onChanged: (value) {
                    setState(() {
                      isEmpty = value.toString().length == 0;
                    });
                  },
                  onTap: () {},
                  decoration: InputDecoration(
                    hintText:
                        '${WXLang.$t("authentication_name_wallet", package: ModuleConfig.moduleName)}',
                    helperText:
                        '${WXLang.$t("authentication_tips_wallet", package: ModuleConfig.moduleName)}',
                    helperStyle: TextStyle(color: Colors.black, fontSize: 12.0),
                    border: OutlineInputBorder(
                        borderSide: BorderSide(
                      color: Colors.blueAccent,
                      width: 1.0,
                    )),
                    enabledBorder: OutlineInputBorder(
                        borderSide: BorderSide(
                      color: Colors.blueAccent,
                      width: 1.0,
                    )),
                    focusedBorder: OutlineInputBorder(
                        borderSide: BorderSide(
                      color: Colors.blueAccent,
                      width: 1.0,
                    )),
                  )),
            ),
            SizedBox(
              height: 30.0,
            ),
            FlatButton(
              onPressed: () {
                if (isEmpty) {
                  return;
                }

                /// 暂挂属性值
                WalletInfo().walletName = _walletNameEditController.text ?? '';

                /// 跳转到PIN码设置界面
                WXNavigator().popAndPushNamed('/pinSetting',
                    moduleName: ModuleConfig.moduleName,
                    context: context,
                    arguments: {
                      'isUpdate': false,
                      'walletSource': widget.walletSource
                    });
              },
              child: Container(
                height: 38.0,
                alignment: Alignment.center,
                padding: EdgeInsets.symmetric(vertical: 0, horizontal: 15),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(3.0),
                  color: isEmpty ? Colors.grey[350] : Theme.of(context).primaryColor,
                ),
                child: Text(
                  '${WXLang.$t("authentication_confirm_wallet", package: ModuleConfig.moduleName)}',
                  style: TextStyle(color: Colors.white, fontSize: 16.0),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
